package de.tempel.pong.ai;

import de.tempel.pong.objects.Ball;
import de.tempel.pong.objects.Racket;

/**
 * Sehr einfache PongCI. Racket folgt einfach dem Ball.
 * 
 * @author mathias
 * 
 */
public class SimplePongAI implements PongAI {

	protected Ball ball;
	protected Racket racket;

	/**
	 * 
	 * @param ball
	 *            mit dem gespielt wird
	 * @param racket
	 *            der gesteuert wird
	 */
	public SimplePongAI(Ball ball, Racket racket) {
		this.ball = ball;
		this.racket = racket;
	}

	@Override
	public void calculateNextPosition() {
		Double ballPositionY = ball.getPosition().getY();
		Double racketPositionY = racket.getPosition().getY();

		Double ballHeight = ball.getHeight();
		Double racketHeight = ball.getHeight();

		// Racket is in CorrectPosition
		if (ballPositionY > racketPositionY
				&& ballPositionY + ballHeight < racketPositionY + racketHeight) {
			return;
		}

		// Zu tief
		if (ballPositionY < racketPositionY) {
			racket.moveUp();
			return;
		}

		// Zu Hoch
		if (ballPositionY + ballHeight > racketPositionY + racketHeight) {
			racket.moveDown();
			return;
		}

	}
}
